from OCC.Core.BRepFilletAPI import BRepFilletAPI_MakeChamfer
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Core.TopAbs import TopAbs_EDGE
from OCC.Core.TopExp import topexp_MapShapes
from OCC.Core.TopTools import TopTools_IndexedMapOfShape
from OCC.Display.OCCViewer import rgb_color
from OCC.Display.SimpleGui import init_display
from OCC.Display.wxDisplay import wxViewer3d


def chamfer(distance):
    """倒角"""
    box = BRepPrimAPI_MakeBox(10, 10, 10).Shape()
    chamfer = BRepFilletAPI_MakeChamfer(box)
    edegMap = TopTools_IndexedMapOfShape()
    topexp_MapShapes(box, TopAbs_EDGE, edegMap)

    edge = edegMap.FindKey(1)  # index从1开始，id是从0开始的
    chamfer.Add(distance, edge)
    return chamfer.Shape()


if __name__ == '__main__':
    display, start_display, add_menu, add_functionto_menu = init_display()
    shape = chamfer(2)
    display.DisplayShape(shape)
    # wxViewer3d.GetWinId(shape)
    start_display()
